﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using WarehouseManagement.DataAccess;

namespace WarehouseManagement.BusinessLogic.DTO
{
    public partial class CustomerDTO : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private int _Id;

        private string _firstName;

        private string _lastName;

        private string _Address;

        private string _Phone;

        private string _Mobile;

        private string _Fax;

        private string _Email;

        private string _BankName;

        private string _BankAccount;

        private string _YahooAccount;

        private string _SkypeAccount;

        private string _ContactPerson;

        private bool _IsActive;



        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnIdChanging(int value);
        partial void OnIdChanged();
        partial void OnFirstNameChanging(string value);
        partial void OnFirstNameChanged();
        partial void OnAddressChanging(string value);
        partial void OnAddressChanged();
        partial void OnPhoneChanging(string value);
        partial void OnPhoneChanged();
        partial void OnMobileChanging(string value);
        partial void OnMobileChanged();
        partial void OnFaxChanging(string value);
        partial void OnFaxChanged();
        partial void OnEmailChanging(string value);
        partial void OnEmailChanged();
        partial void OnBankNameChanging(string value);
        partial void OnBankNameChanged();
        partial void OnBankAccountChanging(string value);
        partial void OnBankAccountChanged();
        partial void OnYahooAccountChanging(string value);
        partial void OnYahooAccountChanged();
        partial void OnSkypeAccountChanging(string value);
        partial void OnSkypeAccountChanged();
        partial void OnContactPersonChanging(string value);
        partial void OnContactPersonChanged();
        partial void OnIsActiveChanging(bool value);
        partial void OnIsActiveChanged();
        #endregion

        public CustomerDTO()
        {
            OnCreated();
        }

        public string FullName
        {
            get { return string.Format("{0} {1}", LastName, FirstName); }
        }
        public int Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                if ((this._Id != value))
                {
                    this.OnIdChanging(value);
                    this.SendPropertyChanging();
                    this._Id = value;
                    this.SendPropertyChanged("Id");
                    this.OnIdChanged();
                }
            }
        }

        public string FirstName
        {
            get
            {
                return this._firstName;
            }
            set
            {
                if ((this._firstName != value))
                {
                    this.OnFirstNameChanging(value);
                    this.SendPropertyChanging();
                    this._firstName = value;
                    this.SendPropertyChanged("FirstName");
                    this.OnFirstNameChanged();
                }
            }
        }

        public string LastName
        {
            get
            {
                return this._lastName;
            }
            set
            {
                if ((this._lastName != value))
                {

                    this._lastName = value;
                    this.SendPropertyChanged("LastName");

                }
            }
        }

        public string Address
        {
            get
            {
                return this._Address;
            }
            set
            {
                if ((this._Address != value))
                {
                    this.OnAddressChanging(value);
                    this.SendPropertyChanging();
                    this._Address = value;
                    this.SendPropertyChanged("Address");
                    this.OnAddressChanged();
                }
            }
        }

        public string Phone
        {
            get
            {
                return this._Phone;
            }
            set
            {
                if ((this._Phone != value))
                {
                    this.OnPhoneChanging(value);
                    this.SendPropertyChanging();
                    this._Phone = value;
                    this.SendPropertyChanged("Phone");
                    this.OnPhoneChanged();
                }
            }
        }

        public string Mobile
        {
            get
            {
                return this._Mobile;
            }
            set
            {
                if ((this._Mobile != value))
                {
                    this.OnMobileChanging(value);
                    this.SendPropertyChanging();
                    this._Mobile = value;
                    this.SendPropertyChanged("Mobile");
                    this.OnMobileChanged();
                }
            }
        }

        public string Fax
        {
            get
            {
                return this._Fax;
            }
            set
            {
                if ((this._Fax != value))
                {
                    this.OnFaxChanging(value);
                    this.SendPropertyChanging();
                    this._Fax = value;
                    this.SendPropertyChanged("Fax");
                    this.OnFaxChanged();
                }
            }
        }

        public string Email
        {
            get
            {
                return this._Email;
            }
            set
            {
                if ((this._Email != value))
                {
                    this.OnEmailChanging(value);
                    this.SendPropertyChanging();
                    this._Email = value;
                    this.SendPropertyChanged("Email");
                    this.OnEmailChanged();
                }
            }
        }

        public string BankName
        {
            get
            {
                return this._BankName;
            }
            set
            {
                if ((this._BankName != value))
                {
                    this.OnBankNameChanging(value);
                    this.SendPropertyChanging();
                    this._BankName = value;
                    this.SendPropertyChanged("BankName");
                    this.OnBankNameChanged();
                }
            }
        }

        public string BankAccount
        {
            get
            {
                return this._BankAccount;
            }
            set
            {
                if ((this._BankAccount != value))
                {
                    this.OnBankAccountChanging(value);
                    this.SendPropertyChanging();
                    this._BankAccount = value;
                    this.SendPropertyChanged("BankAccount");
                    this.OnBankAccountChanged();
                }
            }
        }

        public string YahooAccount
        {
            get
            {
                return this._YahooAccount;
            }
            set
            {
                if ((this._YahooAccount != value))
                {
                    this.OnYahooAccountChanging(value);
                    this.SendPropertyChanging();
                    this._YahooAccount = value;
                    this.SendPropertyChanged("YahooAccount");
                    this.OnYahooAccountChanged();
                }
            }
        }

        public string SkypeAccount
        {
            get
            {
                return this._SkypeAccount;
            }
            set
            {
                if ((this._SkypeAccount != value))
                {
                    this.OnSkypeAccountChanging(value);
                    this.SendPropertyChanging();
                    this._SkypeAccount = value;
                    this.SendPropertyChanged("SkypeAccount");
                    this.OnSkypeAccountChanged();
                }
            }
        }

        public string ContactPerson
        {
            get
            {
                return this._ContactPerson;
            }
            set
            {
                if ((this._ContactPerson != value))
                {
                    this.OnContactPersonChanging(value);
                    this.SendPropertyChanging();
                    this._ContactPerson = value;
                    this.SendPropertyChanged("ContactPerson");
                    this.OnContactPersonChanged();
                }
            }
        }

        public bool IsActive
        {
            get
            {
                return this._IsActive;
            }
            set
            {
                if ((this._IsActive != value))
                {
                    this.OnIsActiveChanging(value);
                    this.SendPropertyChanging();
                    this._IsActive = value;
                    this.SendPropertyChanged("IsActive");
                    this.OnIsActiveChanged();
                }
            }
        }


        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }


    }

    public static class CustomerDTOExtensions
    {
        public static CustomerDTO ToDTO(this Customer entity)
        {
            return new CustomerDTO()
            {
                Address = entity.Address,
                BankAccount = entity.BankAccount,
                BankName = entity.BankName,
                ContactPerson = entity.ContactPerson,
                Email = entity.Email,
                Fax = entity.Fax,
                FirstName = entity.FirstName,
                Id = entity.Id,
                IsActive = entity.IsActive,
                LastName = entity.LastName,
                Mobile = entity.Mobile,
                Phone = entity.Phone,
                SkypeAccount = entity.SkypeAccount,
                YahooAccount = entity.YahooAccount
            };
        }

        public static Customer ToEntity(this CustomerDTO dto)
        {
            return new Customer()
            {
                Address = dto.Address,
                BankAccount = dto.BankAccount,
                BankName = dto.BankName,
                ContactPerson = dto.ContactPerson,
                Email = dto.Email,
                Fax = dto.Fax,
                FirstName = dto.FirstName,
                Id = dto.Id,
                IsActive = dto.IsActive,
                LastName = dto.LastName,
                Mobile = dto.Mobile,
                Phone = dto.Phone,
                SkypeAccount = dto.SkypeAccount,
                YahooAccount = dto.YahooAccount
            };
        }
    }
}
